var clientPC = navigator.userAgent.toLowerCase();
var clientVer = parseInt(navigator.appVersion);
var is_ie = ((clientPC.indexOf("msie") != -1) && (clientPC.indexOf("opera") == -1));
var is_win = ((clientPC.indexOf("win")!=-1) || (clientPC.indexOf("16bit") != -1));
var set_on = false;
var IE = navigator.appName.indexOf("Microsoft") != -1;
var nIE = (IE && parseFloat(navigator.appVersion.substring(navigator.appVersion.indexOf("MSIE ") + 5))>=6);

var isSelected = false;
function sc(e) {
	mouseX=e.clientX;
	mouseY=e.clientY;
}

function ins(ch) {
	var bbopen="["+ch+"]";
	var bbclose="[/"+ch+"]";
	var txtarea = (document.new_news.news_body)? document.new_news.body : document.new_news.body ;

	if (isSelected) {
		if (txtarea.createTextRange && txtarea.caretPos) {
			var caretPos = txtarea.caretPos;
			caretPos.text = bbopen+caretPos.text+bbclose;
			storeCaret(txtarea);
			if (txtarea.caretPos.text=="") {
				isSelected=false;
				txtarea.focus();
			}
		}
	} else if (txtarea.selectionEnd) { // Mozilla
		var selLength = txtarea.textLength;
		var selStart = txtarea.selectionStart;
		var selEnd = txtarea.selectionEnd;
		var s1 = (txtarea.value).substring(0,selStart);
		var s2 = (txtarea.value).substring(selStart, selEnd)
		var s3 = (txtarea.value).substring(selEnd, selLength);
		txtarea.value = s1 + bbopen + s2 + bbclose + s3;
		txtarea.focus(selEnd);
	} else {
		txtarea.value += bbopen + bbclose;
	}
}


function insertSmile(ch){
	var bbopen=":"+ch+":";
	var bbclose="";
	var txtarea = (document.new_news.news_body)? document.new_news.body : document.new_news.body ;

	if (isSelected) {
		if (txtarea.createTextRange && txtarea.caretPos) {
			var caretPos = txtarea.caretPos;
			caretPos.text = bbopen+caretPos.text+bbclose;
			storeCaret(txtarea);
			if (txtarea.caretPos.text=="") {
				isSelected=false;
				txtarea.focus();
			}
		}
	} else if (txtarea.selectionEnd) { // Mozilla
		var selLength = txtarea.textLength;
		var selStart = txtarea.selectionStart;
		var selEnd = txtarea.selectionEnd;
		var s1 = (txtarea.value).substring(0,selStart);
		var s2 = (txtarea.value).substring(selStart, selEnd)
		var s3 = (txtarea.value).substring(selEnd, selLength);
		txtarea.value = s1 + bbopen + s2 + bbclose + s3;
		txtarea.focus(selEnd);
	} else {
		txtarea.value += bbopen + bbclose;
	}
}


function sml(text) {
	sl('','', " :"+text+":");
}

function storeCaret(textEl) {
	if (textEl.createTextRange) {
		textEl.caretPos = document.selection.createRange().duplicate();
		isSelected = true;
	}
}
function optz() {
	var o = document.adds;
	if (o) o.style.display='inline';
}